function flat(arr) {
    return arr.reduce((pre, curr) => {
        return pre.concat(Array.isArray(curr) ? flat(curr) : curr)
    }, [])
}



let arr = [1, [2, 3],
    [4, [5, 6]]
];
let res = [];
function myFlat(arr) {
    let len = arr.length;
    for (let i = 0; i < len; i++) {
        if (Array.isArray(arr[i]) == true) {
            myFlat(arr[i]);
        } else res.push(arr[i])
    }
}
myFlat(arr);
console.log(res);


// https://blog.csdn.net/Cloud1209/article/details/116084765
